package com.erp.base.business.service;

import java.util.Date;
import java.util.List;

import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.stereotype.Service;

import com.erp.base.base.CrudService;
import com.erp.base.business.dao.ServerDao;
import com.erp.base.business.entity.Server;
import com.erp.base.common.utils.ShiroUtils;
import com.erp.base.common.utils.StringUtils;
import com.erp.base.system.entity.User;

@Service
public class ServerService extends CrudService<ServerDao, Server, Long> {
	@Override
	public void save(Server server) {
		User user=ShiroUtils.getUser();
		if (server.getIsNewRecord()){ 
			server.setCreateBy(user.getName());
			server.setCreateDate(new Date());
			server.setUpdateBy(user.getName());
			server.setUpdateDate(new Date());
			dao.insert(server);
		}else{
			server.setUpdateBy(user.getName());
			server.setUpdateDate(new Date());
			int i=dao.update(server);
			if(i==0){
				throw new OptimisticLockingFailureException("乐观锁错误!") ;
			}
		}
	}

	public List<Long> findServerIds(String industry) {
		if(StringUtils.isBlank(industry)){
			industry="ERP";
		}
		return dao.findServerIds(industry);
	}

	public List<Server> findAllList() {
		return dao.findList(new Server());
	}
}
